<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
  <!--[if IE 7]>
    <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
  <![endif]-->
  <link rel="stylesheet" href="assets/css/jquery-ui-1.10.3.full.min.css">
  <link rel="stylesheet" href="assets/css/ace.min.css" />
  <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="js/vue.min.js"></script>
    <script type="text/javascript" src="js/axios.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
<title>项目立项</title>
</head>

<body>
<div id="app">
<div class="page-content">
  <div class="Manager_style">
    <span class="title_name">新建项目</span>
    <div class="project_style">
      <ul class="Add_Manager_style clearfix">
       <li><label class="label_name">项目名称</label><input v-model="orders.project_name" type="text"  class="text" style=" width:570px; "/></li>
       <li><label class="label_name">加油地点</label><input v-model="orders.place" type="text"  class="text" style=" width:250px; "/></li>
       <li><label class="label_name">预计加油时间</label> <input v-model="orders.prime_date" class="inline laydate-icon" id="start" style="width:200px; margin-left:10px"/></li>
       <li><label class="label_name">船名</label>

           <el-select v-model="orders.boat_name" placeholder="请选择">
               <el-option
                       v-for="item in boatData"
                       :key="item.name"
                       :label="item.name"
                       :value="item.name">
               </el-option>
           </el-select>
       </li>
       <li><label class="label_name">报价截止时间</label>
           <input  v-model="orders.cut_time" class="inline laydate-icon" id="time1" style="width:200px; margin-left:10px"/>
       </li>
       <li><label class="label_name">询价模板</label>
           <el-select v-model="moduleObj" placeholder="请选择">
               <el-option
                       v-for="item in moduleData"
                       :key="item.m_name"
                       :label="item.m_name"
                       :value="item.m_id">
               </el-option>
           </el-select>
       </li>
      </ul>
    </div>
     <div class="Item_Details">
  <table id="" class="table table-striped table-bordered table-hover">
      <thead>
       <tr>
        <th>产品名称</th>
        <th width="80">采购数量</th>
        <th>单位</th>
        <th width="100">投标当天最高限价（元/吨）</th>
        <th width="100">报价当天最高限价（元/吨）</th>
        <th class="label_name" v-for="i in modulesData">
            <P class="name">{{i.supplier}}</P>
            <P class="price"><span class="right_border">入围价</span><span>最高限价</span></P>
        </th>
       </tr>
      </thead>
     <tbody>
      <tr v-for="(i,index) in modulesData[0].breed">
       <td>{{i}}</td>
       <td><input name="采购数量" type="text" v-model="supsData[index].purchase" class="add_text"  style="width:60px"/></td>
       <td>吨</td>
       <td>{{modulesData[0].now_fix[index]}}</td>
       <td ><input name="报价价格" type="text" class="add_text" v-model="supsData[index].quote_max" style="width:60px"/></td>
       <td class="price" v-for="(j,inx) in modulesData">
           <div class="tb_price right_border">{{ j.finalist[index] }}</div>
       <div class="tb_price"><input name="报价价格" type="text" class="add_text"
                                    v-model="supsData[index].sup_max[inx].sup" style="width:60px"/></div>
       </td>
      </tr>

     </tbody>
     </table>
  </div>
  <div class="Tips_content">
  <h3>询价说明：</h3>
  <textarea name="" cols="" rows="" style=" width:500px; height:220px; margin-left:0"></textarea>
  </div>
  <!--正式做的时删除该内容-->
  <div  style="color:#F30">备注：最高限价=本项目中标价×投标当天的国家发改委发布的江苏省柴油最高零售价÷供货当天的的国家发改委发布的江苏省柴油最 
高零售价 
</div>
 </div>
   <div class="btn_operating">
       <button id="submit" class="btn btn-info" type="button" @click="sub()">提交</button>
       <button class="btn btn-warning" type="button" @click="store()">暂存项目</button>
</div>
</div>
</div>
<script src="assets/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="assets/layer/layer.js" type="text/javascript"></script>
<script src="assets/laydate/laydate.js" type="text/javascript"></script>
<script>
laydate({
    elem: '#start', 
    event: 'focus' 
});
laydate({
    elem: '#time1', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
    event: 'focus' ,//响应事件。如果没有传入event，则按照默认的click
	format: 'YYYY-MM-DD hh:mm',
    min: laydate.now(), //设定最小日期为当前日期
    max: '2099-06-16 23:59', //最大日期
    istime: true,
    istoday: false,
});
/***判断用户添加文本**/
 jQuery(document).ready(function(){  
 
  $("#submit").click(function(){
	// var num=0;
     var str="";
     $("input[type$='text'],select").each(function(n){
          if($(this).val()=="")
          {
              // num++;
			   layer.alert(str+=""+$(this).attr("name")+"不能为空！\r\n",{
                title: '提示框',				
				icon:0,				
          }); 
             // layer.msg(str+=""+$(this).attr("name")+"不能为空！\r\n");
             layer.close(index);
          }
		  
     });
    
});
 });
</script>

<script>

    new Vue({
        el:'#app',
        data:{
            //模板名称数据
            moduleData:[],
            //模板数据
            modulesData:[],
            //船名数据
            boatData:[],
            //模板名称
            moduleObj:1,
            //存放数据的模板
            supsData:[],
            orders:{
                project_name:'',
                prime_date:'',
                place:'',
                boat_name:'',
                cut_time:'',
                o_type:'',
                m_id:0
            },
            //传入过来的o_id
            o_id:0,
            //是否是第一次过来
            show:true
        },
        methods:{
            getInfo(){
                let mn =parseInt(this.moduleObj)
                axios.get("modules/findModule.do?m_id="+mn).then(dt =>{
                    this.modulesData = [];
                    for (let i = 0; i < dt.data.length; i++) {
                        let fn=JSON.stringify(dt.data[i].breed)
                        let comData = {
                            ms_id:dt.data[i].ms_id.split(","),
                            supplier:dt.data[i].supplier,
                            breed:fn.split(","),
                            finalist: dt.data[i].finalist.split(","),
                            now_fix:dt.data[i].now_fix.split(",")

                        };
                        this.modulesData.push(comData)

                }
                    this.supsData=[]
                    if (this.o_id !== 'default_value' & this.show) {
                            console.log("o_id="+this.o_id)
                        axios.get("modules/supSer.do?o_id=" + this.o_id).then(dt => {
                            for (let i = 0; i < dt.data.length; i++) {
                                console.log(dt.data)
                                let supObj = {
                                    ms_id: dt.data[i].ms_id.split(","),
                                    o_id: this.o_id, // 根据实际情况调整赋值
                                    purchase: dt.data[i].purchase,
                                    quote_max: dt.data[i].quote_max,
                                    sup_max: []
                                }

                                let supMaxArr = dt.data[i].sup_max.split(",");
                                for (let j = 0; j < supMaxArr.length; j++) {
                                    let obj = {
                                        sup: supMaxArr[j]
                                    }
                                    supObj.sup_max.push({...obj})
                                }
                                this.$set(this.supsData, i, supObj);
                                this.supsData.push(supObj)
                            }
                            console.log(this.supsData)
                        })
                            axios.get("orders/idSer.do?o_id=" + this.o_id).then(dt => {
                                this.orders = dt.data
                            })
                            this.show=false
                        } else {
                            for (let i = 0; i < this.modulesData[0].breed.length; i++) {
                                let supObj = {
                                    ms_id: [],
                                    o_id: 0,
                                    purchase: 0,
                                    quote_max: 0,
                                    sup_max: []
                                }
                                for (let j = 0; j < this.modulesData.length; j++) {
                                    let obj = {
                                        sup: 0
                                    }
                                    supObj.ms_id.push(this.modulesData[j].ms_id[i])
                                    supObj.sup_max.push({...obj})
                                }
                                this.supsData.push({...supObj})
                            }
                        }

            })

        },
            sub(){
                this.orders.o_type="待响应"
                this.orders.m_id=parseInt(this.moduleObj)
                if(this.o_id !== 'default_value'){
                    axios.get("modules/deleteSO.do?o_id="+this.o_id).then
                }
                axios.get("modules/ordersAll.do",{
                    params:this.orders
                }).then(dt =>{
                    for (let i = 0; i < this.supsData.length; i++) {
                        let supMax =[]
                        for (let j = 0; j < this.supsData[i].sup_max.length; j++) {
                            supMax.push(this.supsData[i].sup_max[j].sup)
                        }
                        let sup={
                            ms_id:this.supsData[i].ms_id.join(","),
                            o_id:parseInt(dt.data),
                            purchase: parseInt(this.supsData[i].purchase),
                            quote_max: parseInt(this.supsData[i].quote_max),
                            sup_max: supMax.join(",")
                        }
                        axios.get("modules/addSup.do",{
                            params: sup
                        })
                    }
                })
                this.$message({
                    type: 'success',
                    message: '提交成功!'
                });
            },
            store(){
                this.orders.o_type="暂存"
                this.orders.m_id=parseInt(this.moduleObj)
                axios.get("modules/ordersAll.do",{
                    params:this.orders
                }).then(dt =>{
                    for (let i = 0; i < this.supsData.length; i++) {
                        let supMax =[]
                        for (let j = 0; j < this.supsData[i].sup_max.length; j++) {
                            supMax.push(this.supsData[i].sup_max[j].sup)
                        }
                        let sup={
                            ms_id:this.supsData[i].ms_id.join(","),
                            o_id:parseInt(dt.data),
                            purchase: parseInt(this.supsData[i].purchase),
                            quote_max: parseInt(this.supsData[i].quote_max),
                            sup_max: supMax.join(",")
                        }
                        axios.get("modules/addSup.do",{
                            params: sup
                        })
                    }
                })
                this.$message({
                    type: 'success',
                    message: '暂存成功!'
                });
            }

    },
        watch:{
            moduleObj(){
                this.getInfo()
            }
        },
        mounted(){
            let urlParams = new URLSearchParams(window.location.search);
            if (urlParams.has('o_id')) {

                this.o_id = urlParams.get('o_id');
            } else {
                this.o_id = 'default_value'; // 设置默认值
            }
            if(urlParams.has('m_id')){
                this.moduleObj=urlParams.get("m_id")
                console.log(this.moduleObj)
            }
            axios.get("modules/findAll.do").then(dt =>{
                this.moduleData=dt.data
            })
            axios.get("modules/shopAll.do").then(dt =>{
                this.boatData=dt.data
            })
            this.getInfo()
        }
    })
</script>
</body>
</html>
